<?php 
namespace Admin\Controller;

class PagesController extends BaseController
{
	
/**
客户案例显示

**/
	public function change()
	{
		$pages = D("pages");
	  
	     $result = $pages -> select();
	     foreach ($result as $k => $v) {
	        $result[$k] = $v;
	        $result[$k]['img'] = "https://project.csnet.net.cn".substr($v['img'], 8);
	   	}
	   	$count = count($result);
	   
	  	$this -> assign('result', $result);
	  	$this -> assign('count', $count);
		
		$this->display();
	}
	/**
	客户案例添加

	**/
	public function photo_add()
	{

		 $pages = D('pages');
	        if ($_POST) {
	         
	            $cfg = array('rootPath' => './../api/upload/pages/', 'autoSub' => false, );

	            $upload = new \Think\Upload($cfg);
	                // 图片上传
	            $result = $upload -> upload($_FILES);
	            $bigpathname = $upload -> rootPath;

	                if (!$result) {// 上传错误提示错误信息
	                    $this -> error($upload -> getError());

	                } else {// 上传成功 获取上传文件信息
	                    foreach ($result as $file) {
	                        //图片地址
	                        $dizi = $bigpathname . $file['savepath'] . $file['savename'];
	                    }
	                }

	                 $arr = array('img' => $dizi, 'position' => $_POST['name']);
	                   
	                $id = $pages -> add($arr);
	                
	                if ($id) {
	                    $this -> success('新增成功', 'change');
	                }
	            } else {

	              
	                $this -> display();

	            }
	}
	/**
	客户案例修改

	**/
	public function photo_save($id)
	{
		$customer_case = D('pages');
       if($_POST){

            $cfg = array('rootPath' => './../api/upload/pages/', 'autoSub' => false, );

            $upload = new \Think\Upload($cfg);
                // 图片上传
            $result = $upload -> upload($_FILES);
            $bigpathname = $upload -> rootPath;

                if (!$result) {// 上传错误提示错误信息

                    $customer_cases = $customer_case -> where("id = {$id}") -> find();
                    $dizi =$customer_cases['img'];
                
                } else {// 上传成功 获取上传文件信息
                    foreach ($result as $file) {
                        //图片地址
                        $dizi = $bigpathname . $file['savepath'] . $file['savename'];
                    }
                }

               $arr = array('img' => $dizi);
               
           $id = $customer_case -> where("id = {$id}") -> save($arr);
                
                if($id){
                    $this -> success('新增成功', U('Admin/Pages/change'));
                }
            }else{

                $customer_case  = $customer_case -> where("id = {$id}") -> find();
                $customer_case['img'] = "https://project.csnet.net.cn".substr($customer_case['img'], 8);
                $this -> assign('info', $customer_case);
                $this -> display();

            }
	}







	}